package org.apache.solr.ocean.core;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.apache.lucene.index.Term;
import org.apache.lucene.search.Query;

public class Deletes implements Serializable {
	private static final long serialVersionUID = 1l;
	private List<Term> terms = new ArrayList<Term>();
	private List<DeleteByQuery> deleteByQueries = new ArrayList<DeleteByQuery>();
	private long[] docIds;
	
	public Deletes() {}
	
	public void merge(Deletes deletes) {
		terms.addAll(deletes.getTerms());
		deleteByQueries.addAll(deletes.getDeleteByQueries());
	}
	
	public boolean hasDocIds() {
		return docIds != null;
	}
	
	void setDocIds(long[] docIds) {
		assert docIds == null;
  	this.docIds = docIds;
  }
	
	public void addTerm(Term term) {
		terms.add(term);
	}
	
	public void addDeleteByQuery(DeleteByQuery deleteByQuery) {
		deleteByQueries.add(deleteByQuery);
	}
	
	public long[] getDocIds() {
		return docIds;
	}
	
	public boolean hasDeletes() {
		// TODO: implement
		return true;
	}
	
	public boolean hasDeleteByQueries() {
		if (deleteByQueries != null && deleteByQueries.size() > 0) return true;
  	return false;
	}
	
	public List<DeleteByQuery> getDeleteByQueries() {
		return deleteByQueries;
	}
	
	public static class DeleteByQuery implements Serializable {
		private Query query;
		
	  public DeleteByQuery(Query query) {
	  	this.query = query;
	  }
	  
	  public Query getQuery() {
	  	return query;
	  }
	}
	
	public List<Term> getTerms() {
		return terms;
	}
	
  public boolean hasTerms() {
  	if (terms != null && terms.size() > 0) return true;
  	return false;
  }
}
